using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Utils.Drawing;
using DevExpress.XtraTreeList;

namespace Comteck.Winforms.Extensions {
  /// <summary>
  /// 
  /// </summary>
  public static class TreeListExtensions {
    /// <summary>
    /// 设置行号
    /// </summary>
    /// <param name="treeList"></param>
    /// <param name="indicatorWidth"></param>
    /// <returns></returns>
    public static TreeList SetRowNumber(this TreeList treeList, int indicatorWidth = 50) {
      treeList.IndicatorWidth = indicatorWidth;
      treeList.CustomDrawNodeIndicator += (sender, e) => {
        var tmpTree = sender as TreeList;
        if (e.ObjectArgs is IndicatorObjectInfoArgs args) {
          var rowNum = tmpTree.GetVisibleIndexByNode(e.Node) + 1;
          //tree.IndicatorWidth = rowNum.ToString().Length * 10 + 10;
          args.DisplayText = rowNum.ToString();
        }
      };

      return treeList;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="treeList"></param>
    /// <returns></returns>
    public static TreeList SetAppearanceColor(this TreeList treeList) {
      treeList.Appearance.FocusedRow.BackColor = System.Drawing.Color.FromArgb(180, 225, 255);
      treeList.Appearance.FocusedRow.ForeColor = System.Drawing.Color.Black;
      treeList.Appearance.FocusedRow.Options.UseBackColor = true;
      treeList.Appearance.FocusedRow.Options.UseForeColor = true;

      treeList.Appearance.SelectedRow.BackColor = System.Drawing.Color.FromArgb(180, 225, 255);
      treeList.Appearance.SelectedRow.ForeColor = System.Drawing.Color.Black;
      treeList.Appearance.SelectedRow.Options.UseBackColor = true;
      treeList.Appearance.SelectedRow.Options.UseForeColor = true;

      return treeList;
    }
  }
}
